package com.vdong.trade.order.web.controller;

import com.alibaba.fastjson.JSON;
import com.vdong.trade.order.common.contract.ApiContract;
import com.vdong.trade.order.common.foundation.FoundationController;
import com.vdong.trade.order.entity.dto.param.OrderStateMachineParamDTO;
import com.vdong.trade.order.entity.po.ChannelCurvePO;
import com.vdong.trade.order.entity.po.OrderStateMachineParamPO;
import com.vdong.trade.order.service.DisbOrderService;
import com.vdong.trade.order.service.OrderService;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.lamb.framework.common.userDTO.AccountSystemUserInfoDTO;
import org.lamb.framework.common.util.BeanPlasticityUtill;
import org.lamb.framework.core.security.LambPrincipalFactoryContainer;
import org.lamb.framework.core.security.LambUnifyAuthTokenHandler;
import org.lamb.framework.core.templete.LambResponseTemplete;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Mono;

import javax.annotation.Resource;
import javax.validation.Valid;
import javax.validation.constraints.NotNull;

/**
 * @description:
 * @author: Mr.WangGang
 * @create: 2018-11-14 上午 11:42
 **/
@RestController
@Slf4j
public class Test extends FoundationController {

    @Resource
    private OrderService orderService;

    @RequestMapping(value = ApiContract.I000000000, method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE)
    public Mono<LambResponseTemplete> validate(@RequestBody @Valid @NotNull OrderStateMachineParamPO param) {
        try {
            return returning(orderService.execute(BeanPlasticityUtill.copy(OrderStateMachineParamDTO.class, param)));
        } catch (Exception e) {
            log.info("订单捕获到的异常为:[{}]", e);
            return returning(e.getMessage());
        }
    }

    @Resource
    private LambUnifyAuthTokenHandler lambUnifyAuthTokenHandler;

    @RequestMapping(value = "/login", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE)
    public Mono<LambResponseTemplete> login() {

        return returning(lambUnifyAuthTokenHandler.setPrincipalByToken("1",
                "{\"principalKey\":1}", "disb"));
    }

}
